A very basic introduction to Time series analysis (TSA)

When we measure the same variable (whichever it is) many times in different times (e.g., daily temperature, monthly moth abundance, yearly inflation) we can build a times series dataset, allowing to conduct very interesting analyses. With TSA we can assess trends without the noise of temporal variation (e.g., seasons) in our data, and therefore making more robust inferences.

#Loading required packages
library(TSA)
library(forecast)
library(astsa)

#Loading work data
data<-read.table("data/19_bird_data.txt", header=T)
attach(data)
names(data)
##  [1] "year"    "month"   "aphspiC" "aphspiN" "carbarC" "carbarN" "elaalbC"
##  [8] "elaalbN" "phrpatC" "phrpatN" "troaedC" "troaedN" "turfalC" "turfalN"
## [15] "zoncapC" "zoncapN"

We will use now an unpublished dataset of bird abundance in two habitat types (notro and canelo forests) with monthly records for 12 year (yeah, a lot of work).

First, we need to convert each variable into a TSA object:

aphcan<-ts(aphspiC, start=c(2003, 1), end=c(2015, 12), frequency=12)
aphnot<-ts(aphspiN, start=c(2003, 1), end=c(2015, 12), frequency=12)
carcan<-ts(carbarC, start=c(2003, 1), end=c(2015, 12), frequency=12)
carnot<-ts(carbarN, start=c(2003, 1), end=c(2015, 12), frequency=12)
elacan<-ts(elaalbC, start=c(2003, 1), end=c(2015, 12), frequency=12)
elanot<-ts(elaalbN, start=c(2003, 1), end=c(2015, 12), frequency=12)
phrcan<-ts(phrpatC, start=c(2003, 1), end=c(2015, 12), frequency=12)
phrnot<-ts(phrpatN, start=c(2003, 1), end=c(2015, 12), frequency=12)
trocan<-ts(troaedC, start=c(2003, 1), end=c(2015, 12), frequency=12)
tronot<-ts(troaedN, start=c(2003, 1), end=c(2015, 12), frequency=12)
turcan<-ts(turfalC, start=c(2003, 1), end=c(2015, 12), frequency=12)
turnot<-ts(turfalN, start=c(2003, 1), end=c(2015, 12), frequency=12)
zoncan<-ts(zoncapC, start=c(2003, 1), end=c(2015, 12), frequency=12)
zonnot<-ts(zoncapN, start=c(2003, 1), end=c(2015, 12), frequency=12)

Now that we have those object, we can plot each variable:

plot(aphcan,ylab='Rayadito abundance (Canelo)')

plot(aphnot,ylab='Rayadito abundance (Notro)')

plot(carcan,ylab='Jilguero abundance (Canelo)')

plot(carnot,ylab='Jilguero abundance (Notro)')

plot(elacan,ylab='Fiofio abundance (Canelo)')

plot(elanot,ylab='Fiofio abundance (Notro)')

plot(phrcan,ylab='Cometocino abundance (Canelo)')

plot(phrnot,ylab='Cometocino abundance (Notro)')

plot(trocan,ylab='Chercan abundance (Canelo)')

plot(tronot,ylab='Chercan abundance (Notro)')

plot(turcan,ylab='Zorzal abundance (Canelo)')

plot(turnot,ylab='Zorzal abundance (Notro)')

plot(zoncan,ylab='Chincol abundance (Canelo)')

plot(zonnot,ylab='Chincol abundance (Notro)')

Holy Molly! a lot of data! Let’s unify habitat data by species:

aphspi<-cbind(aphspiC,aphspiN)
carbar<-cbind(carbarC,carbarN)
elaalb<-cbind(elaalbC,elaalbN)
phrpat<-cbind(phrpatC,phrpatN)
troaed<-cbind(troaedC,troaedN)
turfal<-cbind(turfalC,turfalN)
zoncap<-cbind(zoncapC,zoncapN)

And convert them in TSA objects:

rayadito<-ts(aphspi, start=c(2003, 1), end=c(2015, 12), frequency=12)
jilguero<-ts(carbar, start=c(2003, 1), end=c(2015, 12), frequency=12)
fiofio<-ts(elaalb, start=c(2003, 1), end=c(2015, 12), frequency=12)
cometocino<-ts(phrpat, start=c(2003, 1), end=c(2015, 12), frequency=12)
chercan<-ts(troaed, start=c(2003, 1), end=c(2015, 12), frequency=12)
zorzal<-ts(turfal, start=c(2003, 1), end=c(2015, 12), frequency=12)
chincol<-ts(zoncap, start=c(2003, 1), end=c(2015, 12), frequency=12)

And plot them again:

plot(rayadito, main="Aphrastura spinicauda")

plot(jilguero, main="Carduelis barbata")

plot(fiofio, main="Elaenia albiceps")

plot(cometocino, main="Phrygilus patagonicus")

plot(chercan, main="Troglodytes aedon")

plot(zorzal, main="Turdus falcklandii")

plot(chincol, main="Zonotrichia capensis")

Autocorrelation functions

As we dealt with spatial autocorrelation on lesson 15, in TSA we will deal with temporal autocorrelation, that has the same principle (the shorter the measurement interval, the more similar a variable would be). In this case, we will estimate the autocorrelation function (ACF) for each variable:

acf(as.vector(aphcan),lag.max=36, main="ACF Rayadito Canelo")

acf(as.vector(aphnot),lag.max=36, main="ACF Rayadito Notro")

acf(as.vector(carcan),lag.max=36, main="ACF Jilguero Canelo")

acf(as.vector(carnot),lag.max=36, main="ACF Jilguero Notro")

acf(as.vector(elacan),lag.max=36, main="ACF Fiofio Canelo")

acf(as.vector(elanot),lag.max=36, main="ACF Fiofio Notro")

acf(as.vector(phrcan),lag.max=36, main="ACF Cometocino Canelo")

acf(as.vector(phrnot),lag.max=36, main="ACF Cometocino Notro")

acf(as.vector(trocan),lag.max=36, main="ACF Chercan Canelo")

acf(as.vector(tronot),lag.max=36, main="ACF Chercan Notro")

acf(as.vector(turcan),lag.max=36, main="ACF Zorzal Canelo")

acf(as.vector(turnot),lag.max=36, main="ACF Zorzal Notro")

acf(as.vector(zoncan),lag.max=36, main="ACF Chincol Canelo")

acf(as.vector(zonnot),lag.max=36, main="ACF Chincol Notro")

It’s common to find regular “waves” of autocorrelation, as they are given by seasonality. This analysis is useful to understand the temporal variation in any phenomenon that we are studying!

Decomposing time series data

This is my favorite part! We can decompose a time series data into four elements: the data itself, the seasonal variation, the trend, and the remainder (error). We also can plot the variation within each month across years, and annual variation across sampling years. We will use only two species (one resident and one migratory) as an example here:

#Rayadito-Canelo
decompose(aphcan)
## $x
##             Jan        Feb        Mar        Apr        May        Jun
## 2003  7.0850202  2.5248275  3.9407314  5.1695616  2.6586317  8.8113490
## 2004  6.5971764  4.7471171  1.9413036  5.5741360  3.9841503  3.0158028
## 2005  2.3619220  4.0345014  2.7329374  6.2751660  7.4578334  6.9220120
## 2006 11.1505593  9.2762739 14.7637795 12.7519612 13.0383958  4.5471080
## 2007  0.9587728  0.0000000  7.8485688  4.7728900  1.8450184 10.0967040
## 2008  7.8895464  7.5322474  5.3806044  5.7974936  2.9285435  1.9599068
## 2009  1.9656664  7.6736964  8.2051282  5.6410256  7.6923077 10.7599055
## 2010  2.2624434  5.4240631  9.0905156 10.1382489  6.3572791 12.6047050
## 2011  5.6980057  5.8496636  4.0518639  4.1907245  2.8490028  3.3238367
## 2012  7.3902705  6.3398140 12.1794872  3.8461538 11.5384615  5.5555556
## 2013  1.3603468  4.3272413  5.7354926  3.6521342  3.8948393  2.7195027
## 2014  2.1680687  2.9749256  5.4439545  3.1730203  3.6505867  3.2796661
## 2015  4.7520048  5.5660692  6.6312997  6.0798308  3.1080031  0.8140008
##             Jul        Aug        Sep        Oct        Nov        Dec
## 2003  3.8639279  2.0917220  2.7951699  1.2621376  0.9802864  1.6876498
## 2004  1.7526333  2.6746550  2.2704568  0.4658052  0.6625969  1.2903464
## 2005  3.1655587  0.7723200  1.4732459  1.1393986  1.3000351  2.1180719
## 2006  1.4240957  0.4709872  0.0000000  0.9186111  1.4249074  0.4594321
## 2007  1.6092694  1.6686134  0.5574136  0.0000000  0.5554013  1.9180421
## 2008  3.6805300  1.4869151  1.4670644  2.2087407  1.9733986  1.6527590
## 2009  1.5061299  2.3076923  0.7820035  0.0000000  0.5128205  0.9473285
## 2010  1.3805798  1.3733748  1.4513788  2.1367521  2.9416091  2.4654832
## 2011  2.8490028  4.0064103  1.6436555  1.0957703  0.4748338  2.1367521
## 2012  1.9230769  1.9230769  1.2820513  0.4273504  1.7101618  2.5641026
## 2013  1.1257036  1.7094017  0.8249124  0.8165932  0.9380863  0.1797268
## 2014  3.8693701  0.7279786  1.2610340  1.1984775  2.3000256  0.2747253
## 2015  4.3215212  3.8850039  0.7631258  1.1094675  0.3750516  1.6662038
## 
## $seasonal
##            Jan       Feb       Mar       Apr       May       Jun       Jul
## 2003  0.962131  1.720218  3.409324  2.407564  2.114498  1.887865 -1.251081
## 2004  0.962131  1.720218  3.409324  2.407564  2.114498  1.887865 -1.251081
## 2005  0.962131  1.720218  3.409324  2.407564  2.114498  1.887865 -1.251081
## 2006  0.962131  1.720218  3.409324  2.407564  2.114498  1.887865 -1.251081
## 2007  0.962131  1.720218  3.409324  2.407564  2.114498  1.887865 -1.251081
## 2008  0.962131  1.720218  3.409324  2.407564  2.114498  1.887865 -1.251081
## 2009  0.962131  1.720218  3.409324  2.407564  2.114498  1.887865 -1.251081
## 2010  0.962131  1.720218  3.409324  2.407564  2.114498  1.887865 -1.251081
## 2011  0.962131  1.720218  3.409324  2.407564  2.114498  1.887865 -1.251081
## 2012  0.962131  1.720218  3.409324  2.407564  2.114498  1.887865 -1.251081
## 2013  0.962131  1.720218  3.409324  2.407564  2.114498  1.887865 -1.251081
## 2014  0.962131  1.720218  3.409324  2.407564  2.114498  1.887865 -1.251081
## 2015  0.962131  1.720218  3.409324  2.407564  2.114498  1.887865 -1.251081
##            Aug       Sep       Oct       Nov       Dec
## 2003 -1.831601 -2.301899 -2.659298 -2.321975 -2.135746
## 2004 -1.831601 -2.301899 -2.659298 -2.321975 -2.135746
## 2005 -1.831601 -2.301899 -2.659298 -2.321975 -2.135746
## 2006 -1.831601 -2.301899 -2.659298 -2.321975 -2.135746
## 2007 -1.831601 -2.301899 -2.659298 -2.321975 -2.135746
## 2008 -1.831601 -2.301899 -2.659298 -2.321975 -2.135746
## 2009 -1.831601 -2.301899 -2.659298 -2.321975 -2.135746
## 2010 -1.831601 -2.301899 -2.659298 -2.321975 -2.135746
## 2011 -1.831601 -2.301899 -2.659298 -2.321975 -2.135746
## 2012 -1.831601 -2.301899 -2.659298 -2.321975 -2.135746
## 2013 -1.831601 -2.301899 -2.659298 -2.321975 -2.135746
## 2014 -1.831601 -2.301899 -2.659298 -2.321975 -2.135746
## 2015 -1.831601 -2.301899 -2.659298 -2.321975 -2.135746
## 
## $trend
##           Jan      Feb      Mar      Apr      May      Jun      Jul      Aug
## 2003       NA       NA       NA       NA       NA       NA 3.552258 3.624526
## 2004 3.123744 3.060063 3.062488 3.007445 2.961027 2.931236 2.738213 2.532051
## 2005 3.300611 3.280219 3.167738 3.162587 3.217213 3.278262 3.678943 4.263544
## 2006 6.218831 6.133715 6.059774 5.989189 5.985193 5.921286 5.427518 4.616349
## 2007 2.526048 2.583665 2.656791 2.641741 2.567236 2.591782 2.941340 3.543966
## 2008 3.236059 3.314791 3.345122 3.475055 3.626170 3.674199 3.416317 3.175383
## 2009 4.443328 4.386927 4.392582 4.272007 4.119119 4.028868 4.011841 3.930472
## 2010 4.322538 4.278377 4.267337 4.384259 4.574490 4.738946 4.945351 5.106233
## 2011 3.203874 3.374768 3.492489 3.457127 3.310970 3.194491 3.251305 3.342239
## 2012 4.882767 4.757381 4.655509 4.612591 4.636212 4.705491 4.472050 4.136946
## 2013 2.593391 2.551264 2.523313 2.520484 2.504533 2.373014 2.307320 2.284629
## 2014 2.304707 2.378133 2.355413 2.389496 2.462155 2.522861 2.634483 2.850112
## 2015 3.067408 3.217790 3.328587 3.304132 3.220216 3.197987       NA       NA
##           Sep      Oct      Nov      Dec
## 2003 3.633812 3.567360 3.639447 3.453196
## 2004 2.535344 2.597538 2.771485 3.078980
## 2005 4.983236 5.754388 6.256778 6.390347
## 2006 3.941704 3.321109 2.522257 2.287099
## 2007 3.754978 3.694838 3.782676 3.488790
## 2008 3.298965 3.410134 3.602105 4.167262
## 2009 3.873629 4.097904 4.229662 4.250903
## 2010 4.914022 4.456265 4.062273 3.529392
## 2011 3.701312 4.025606 4.373310 4.828359
## 2012 3.784589 3.508005 3.181437 2.744784
## 2013 2.216135 2.184024 2.153884 2.167047
## 2014 3.007549 3.178139 3.276648 3.151304
## 2015       NA       NA       NA       NA
## 
## $random
##              Jan         Feb         Mar         Apr         May         Jun
## 2003          NA          NA          NA          NA          NA          NA
## 2004  2.51130102 -0.03316349 -4.53050871  0.15912731 -1.09137549 -1.80329796
## 2005 -1.90081966 -0.96593524 -3.84412404  0.70501541  2.12612178  1.75588556
## 2006  3.96959694  1.42234110  5.29468159  4.35520800  4.93870444 -3.26204269
## 2007 -2.52940609 -4.30388248  1.78245377 -0.27641509 -2.83671643  5.61705679
## 2008  3.69135601  2.49723837 -1.37384191 -0.08512568 -2.81212447 -3.60215725
## 2009 -3.43979277  1.56655123  0.40322234 -1.03854510  1.45869054  4.84317240
## 2010 -3.02222546 -0.57453159  1.41385423  3.34642559 -0.33170973  5.97789389
## 2011  1.53200081  0.75467770 -2.84994931 -1.67396587 -2.57646570 -1.75851878
## 2012  1.54537250 -0.13778517  4.11465449 -3.17400112  4.78775071 -1.03779986
## 2013 -2.19517504  0.05575948 -0.19714449 -1.27591379 -0.72419200 -1.54137614
## 2014 -1.09876890 -1.12342572 -0.32078185 -1.62403961 -0.92606718 -1.13105987
## 2015  0.72246583  0.62806101 -0.10661091  0.36813515 -2.22671126 -4.27185089
##              Jul         Aug         Sep         Oct         Nov         Dec
## 2003  1.56275073  0.29879627  1.46325719  0.35407572 -0.33718546  0.37019934
## 2004  0.26550119  1.97420411  2.03701243  0.52756522  0.21308760  0.34711192
## 2005  0.73769588 -1.65962318 -1.20809076 -1.95569090 -2.63476713 -2.13652910
## 2006 -2.75234189 -2.31376119 -1.63980429  0.25680055  1.22462603  0.30807867
## 2007 -0.08099007 -0.04375193 -0.89566461 -1.03553948 -0.90529976  0.56499768
## 2008  1.51529308  0.14313288  0.46999883  1.45790485  0.69326918 -0.37875687
## 2009 -1.25463056  0.20882082 -0.78972552 -1.43860576 -1.39486621 -1.16782832
## 2010 -2.31369075 -1.90125751 -1.16074418  0.33978517  1.20131093  1.07183644
## 2011  0.84877889  2.49577235  0.24424257 -0.27053776 -1.57650080 -0.55586122
## 2012 -1.29789256 -0.38226851 -0.20063828 -0.42135652  0.85070039  1.95506461
## 2013  0.06946400  1.25637357  0.91067702  1.29186703  1.10617758  0.14842546
## 2014  2.48596724 -0.29053248  0.55538478  0.67963706  1.34535284 -0.74083342
## 2015          NA          NA          NA          NA          NA          NA
## 
## $figure
##  [1]  0.962131  1.720218  3.409324  2.407564  2.114498  1.887865 -1.251081
##  [8] -1.831601 -2.301899 -2.659298 -2.321975 -2.135746
## 
## $type
## [1] "additive"
## 
## attr(,"class")
## [1] "decomposed.ts"
fit.aphcan<-stl(aphcan, "periodic")
plot(fit.aphcan, main="Rayadito-Canelo")

monthplot(aphcan, main="Rayadito-Canelo")

seasonplot(aphcan, main="Rayadito-Canelo")

##
#Rayadito-Notro
decompose(aphnot)
## $x
##             Jan        Feb        Mar        Apr        May        Jun
## 2003  6.1050061  1.0229133  1.8743440  2.4238429  0.0000000  0.8841733
## 2004  1.2498334  1.3792089  3.0971578  2.5996309  1.1214911  2.2024168
## 2005  5.4695021  0.7735627  0.0000000  6.2743130 10.7953122  2.6809939
## 2006  1.2797477  1.2501719  5.7850636  7.6086130  2.9871382  1.4792899
## 2007  1.0668943  0.0000000  4.8076923 12.9152245 18.0045943  0.0000000
## 2008  0.7396450  1.5110610  2.9077563  3.2573054  4.9162597  7.2663388
## 2009  1.4827751  3.6641669  7.1794872  7.1794872  5.3846154  4.5969966
## 2010  2.5655279  2.6361575  0.0000000  2.1367521  6.1253355  1.6025641
## 2011  0.0000000  0.6759497  6.8332683  0.9438414  5.1943146  3.7986705
## 2012  1.5172205  0.9506736 17.9487179  4.7008547  7.7787381  9.8181508
## 2013  0.0000000  0.3406087  1.6764058  2.7720028  2.3310023  0.0000000
## 2014  0.3448434  0.2249213  2.9239766  2.5471218  1.4652015  0.8212428
## 2015  0.0000000  0.7692308  0.5656109  0.0000000  3.1185031  0.8867213
##             Jul        Aug        Sep        Oct        Nov        Dec
## 2003  2.3257166  0.7137046  0.0000000  0.9686825  0.8617867  4.5033415
## 2004  5.2151239  1.1249353  0.4814915  0.3789688  0.2117460  2.0143523
## 2005  1.5308075  1.5692182  0.8986341  1.0724873  0.4783179  2.3670720
## 2006  0.6700616  1.5068184  1.0559105  0.0000000  0.5290445  0.5262936
## 2007  0.7938398  3.3444816  0.8361204  1.1072317  0.8325008  0.9861933
## 2008  1.4791951  2.9600979  1.4400576  0.0000000  1.3433477  0.0000000
## 2009  3.0769231  0.5354275  0.0000000  0.7692308  2.0512821  0.0000000
## 2010  3.9083319  1.2922818  0.9496676  1.4245014  0.0000000  0.9496676
## 2011  1.4245014  3.5612536  0.9496676  0.0000000  0.0000000  1.9513718
## 2012  4.5639366  1.2800601  0.8547009  0.0000000  0.0000000  0.4273504
## 2013  1.3262599  0.7849294  0.0000000  0.2070051  0.7987858  2.3093719
## 2014  0.0000000  1.0256410  0.2616431  0.9841745  0.0000000  1.2457178
## 2015  0.8183306  0.0000000  0.0000000  0.2399347  0.4633920  0.2616431
## 
## $seasonal
##             Jan        Feb        Mar        Apr        May        Jun
## 2003 -0.9573984 -1.0780427  2.2202208  2.1569186  3.5181123  0.6951303
## 2004 -0.9573984 -1.0780427  2.2202208  2.1569186  3.5181123  0.6951303
## 2005 -0.9573984 -1.0780427  2.2202208  2.1569186  3.5181123  0.6951303
## 2006 -0.9573984 -1.0780427  2.2202208  2.1569186  3.5181123  0.6951303
## 2007 -0.9573984 -1.0780427  2.2202208  2.1569186  3.5181123  0.6951303
## 2008 -0.9573984 -1.0780427  2.2202208  2.1569186  3.5181123  0.6951303
## 2009 -0.9573984 -1.0780427  2.2202208  2.1569186  3.5181123  0.6951303
## 2010 -0.9573984 -1.0780427  2.2202208  2.1569186  3.5181123  0.6951303
## 2011 -0.9573984 -1.0780427  2.2202208  2.1569186  3.5181123  0.6951303
## 2012 -0.9573984 -1.0780427  2.2202208  2.1569186  3.5181123  0.6951303
## 2013 -0.9573984 -1.0780427  2.2202208  2.1569186  3.5181123  0.6951303
## 2014 -0.9573984 -1.0780427  2.2202208  2.1569186  3.5181123  0.6951303
## 2015 -0.9573984 -1.0780427  2.2202208  2.1569186  3.5181123  0.6951303
##             Jul        Aug        Sep        Oct        Nov        Dec
## 2003 -0.1066131 -0.6358550 -1.6280096 -1.6830169 -1.6692181 -0.8322283
## 2004 -0.1066131 -0.6358550 -1.6280096 -1.6830169 -1.6692181 -0.8322283
## 2005 -0.1066131 -0.6358550 -1.6280096 -1.6830169 -1.6692181 -0.8322283
## 2006 -0.1066131 -0.6358550 -1.6280096 -1.6830169 -1.6692181 -0.8322283
## 2007 -0.1066131 -0.6358550 -1.6280096 -1.6830169 -1.6692181 -0.8322283
## 2008 -0.1066131 -0.6358550 -1.6280096 -1.6830169 -1.6692181 -0.8322283
## 2009 -0.1066131 -0.6358550 -1.6280096 -1.6830169 -1.6692181 -0.8322283
## 2010 -0.1066131 -0.6358550 -1.6280096 -1.6830169 -1.6692181 -0.8322283
## 2011 -0.1066131 -0.6358550 -1.6280096 -1.6830169 -1.6692181 -0.8322283
## 2012 -0.1066131 -0.6358550 -1.6280096 -1.6830169 -1.6692181 -0.8322283
## 2013 -0.1066131 -0.6358550 -1.6280096 -1.6830169 -1.6692181 -0.8322283
## 2014 -0.1066131 -0.6358550 -1.6280096 -1.6830169 -1.6692181 -0.8322283
## 2015 -0.1066131 -0.6358550 -1.6280096 -1.6830169 -1.6692181 -0.8322283
## 
## $trend
##            Jan       Feb       Mar       Apr       May       Jun       Jul
## 2003        NA        NA        NA        NA        NA        NA 1.6046604
## 2004 1.8723062 2.0098328 2.0470295 2.0425203 1.9908638 1.8600709 1.9321826
## 2005 2.7981786 2.6631772 2.6990699 2.7453475 2.7853513 2.8111551 2.6512786
## 2006 2.3230157 2.2845513 2.2885045 2.2503707 2.2077973 2.1332118 2.0476439
## 2007 3.4287019 3.5104286 3.5778400 3.6148168 3.6735954 3.7054019 3.7109290
## 2008 2.4034509 2.4159914 2.4251395 2.4041689 2.3793195 2.3595134 2.3493858
## 2009 3.1257576 3.0913016 2.9302713 2.9023202 2.9638687 2.9933660 3.0384807
## 2010 1.8262421 1.8924197 1.9635248 2.0303972 1.9722301 1.9263295 1.8590020
## 2011 2.0607150 2.0517625 2.1463030 2.0869488 2.0275946 2.0693322 2.1742874
## 2012 4.3475723 4.3833324 4.2843257 4.2803687 4.2803687 4.2168679 4.0901494
## 2013 1.0522691 0.8967355 0.8404925 0.8135052 0.8554131 0.9671134 1.0598994
## 2014 1.0908775 1.0456463 1.0665777 1.1098616 1.1089609 1.0313592 0.9726718
## 2015 0.7722007 0.7635627 0.7099259 0.6680141 0.6563121 0.6346170        NA
##            Aug       Sep       Oct       Nov       Dec
## 2003 1.4172072 1.4830034 1.5412785 1.5953318 1.6969874
## 2004 2.0827668 1.9284833 1.9525469 2.5087345 2.9317511
## 2005 2.4965643 2.7574673 3.0541074 2.7843627 2.4089511
## 2006 1.9866845 1.8938702 2.0742552 2.9210913 3.4851816
## 2007 3.7602545 3.7440514 3.2624741 2.3147135 2.0721304
## 2008 2.4700623 2.7377638 3.0791769 3.2621159 3.1704081
## 2009 3.0407616 2.6987826 2.1895234 2.0102727 1.9163681
## 2010 1.6704296 1.8734738 2.1084887 2.0199916 2.0727035
## 2011 2.2489518 2.7235423 3.3432283 3.6074548 3.9659508
## 2012 4.0015126 3.2980802 2.5396983 2.2323405 1.5962619
## 2013 1.0694476 1.1166094 1.1592215 1.1137764 1.1119198
## 2014 0.9809829 0.9053972 0.7010019 0.6637594 0.7353753
## 2015        NA        NA        NA        NA        NA
## 
## $random
##              Jan         Feb         Mar         Apr         May         Jun
## 2003          NA          NA          NA          NA          NA          NA
## 2004  0.33492561  0.44741879 -1.17009245 -1.59980805 -4.38748498 -0.35278447
## 2005  3.62872190 -0.81157182 -4.91929071  1.37204683  4.49184870 -0.82529151
## 2006 -0.08586951  0.04366329  1.27633834  3.20132362 -2.73877138 -1.34905224
## 2007 -1.40440920 -2.43238596 -0.99036848  7.14348907 10.81288657 -4.40053226
## 2008 -0.70640753  0.17311221 -1.73760398 -1.30378211 -0.98117210  4.21169501
## 2009 -0.68558401  1.65090795  2.02899513  2.12024838 -1.09736561  0.90850032
## 2010  1.69668423  1.82178051 -4.18374555 -2.05056371  0.63499314 -1.01889570
## 2011 -1.10331652 -0.29777013  2.46674448 -3.30002598 -0.35139225  1.03420790
## 2012 -1.87295340 -2.35461607 11.44417149 -1.73643268 -0.01974291  4.90615258
## 2013 -0.09487066  0.52191595 -1.38430746 -0.19842102 -2.04252306 -1.66224375
## 2014  0.21136444  0.25731768 -0.36282188 -0.71965846 -3.16187171 -0.90524675
## 2015  0.18519779  1.08371073 -2.36453578 -2.82493273 -1.05592127 -0.44302598
##              Jul         Aug         Sep         Oct         Nov         Dec
## 2003  0.82766927 -0.06764767  0.14500616  1.11042085  0.93567293  3.63858240
## 2004  3.38955436 -0.32197656  0.18101771  0.10943875 -0.62777044 -0.08517049
## 2005 -1.01385807 -0.29149107 -0.23082363 -0.29860331 -0.63682676  0.79034923
## 2006 -1.27096914  0.15598886  0.79004988 -0.39123832 -0.72282870 -2.12665962
## 2007 -2.81047616  0.22008206 -1.27992140 -0.47222553  0.18700539 -0.25370874
## 2008 -0.76357761  1.12589056  0.33030336 -1.39616000 -0.24955010 -2.33817982
## 2009  0.14505547 -1.86947923 -1.07077304  0.26272426  1.71022738 -1.08413973
## 2010  2.15594295  0.25770717  0.70420337  0.99902956 -0.35077350 -0.29080752
## 2011 -0.64317293  1.94815676 -0.14586514 -1.66021144 -1.93823675 -1.18235068
## 2012  0.58040022 -2.08559751 -0.81536974 -0.85668148 -0.56312245 -0.33668316
## 2013  0.37297356  0.35133671  0.51140016  0.73080041  1.35422750  2.02968035
## 2014 -0.86605878  0.68051307  0.98425545  1.96618939  1.00545864  1.34257090
## 2015          NA          NA          NA          NA          NA          NA
## 
## $figure
##  [1] -0.9573984 -1.0780427  2.2202208  2.1569186  3.5181123  0.6951303
##  [7] -0.1066131 -0.6358550 -1.6280096 -1.6830169 -1.6692181 -0.8322283
## 
## $type
## [1] "additive"
## 
## attr(,"class")
## [1] "decomposed.ts"
fit.aphnot<-stl(aphnot, "periodic")
plot(fit.aphnot, main="Rayadito-Notro")

monthplot(aphnot, main="Rayadito-Notro")

seasonplot(aphnot, main="Rayadito-Notro")

##
#Chincol-Canelo
decompose(zoncan)
## $x
##             Jan        Feb        Mar        Apr        May        Jun
## 2003 1.01214575 0.84160916 0.00000000 0.00000000 0.00000000 0.00000000
## 2004 1.64929410 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
## 2005 0.23619220 0.21234218 0.00000000 0.00000000 0.00000000 0.00000000
## 2006 5.35226847 0.88345466 0.00000000 0.00000000 0.00000000 0.00000000
## 2007 3.35570470 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
## 2008 1.47928994 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
## 2009 0.00000000 0.45139390 0.00000000 0.00000000 0.00000000 0.00000000
## 2010 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
## 2011 2.37416904 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
## 2012 1.92789667 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
## 2013 0.00000000 0.50908721 0.00000000 0.00000000 0.00000000 0.00000000
## 2014 0.08672275 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
## 2015 4.45500446 0.55660692 0.00000000 0.00000000 0.00000000 0.00000000
##             Jul        Aug        Sep        Oct        Nov        Dec
## 2003 0.00000000 0.00000000 0.00000000 0.84142504 0.00000000 0.84382489
## 2004 0.00000000 0.00000000 0.56761420 0.69870786 0.66259685 0.36867039
## 2005 0.00000000 0.00000000 1.47324586 0.22787972 0.21667252 0.00000000
## 2006 0.00000000 0.00000000 1.70523336 0.45930553 0.94993825 0.45943214
## 2007 0.00000000 0.00000000 0.55741360 0.50549643 0.55540128 0.00000000
## 2008 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.55091967
## 2009 0.00000000 0.00000000 0.78200349 0.00000000 0.00000000 0.00000000
## 2010 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
## 2011 0.00000000 0.00000000 0.00000000 0.54788516 0.00000000 0.00000000
## 2012 0.00000000 0.00000000 1.28205128 0.42735043 0.42754044 0.00000000
## 2013 0.00000000 0.00000000 0.00000000 0.61244488 0.00000000 0.00000000
## 2014 0.00000000 0.00000000 0.00000000 0.00000000 0.25555839 0.54945055
## 2015 0.00000000 0.00000000 0.00000000 0.73964497 0.18752579 0.00000000
## 
## $seasonal
##              Jan         Feb         Mar         Apr         May         Jun
## 2003  1.46389075 -0.06141403 -0.27915444 -0.27880104 -0.27909877 -0.27681995
## 2004  1.46389075 -0.06141403 -0.27915444 -0.27880104 -0.27909877 -0.27681995
## 2005  1.46389075 -0.06141403 -0.27915444 -0.27880104 -0.27909877 -0.27681995
## 2006  1.46389075 -0.06141403 -0.27915444 -0.27880104 -0.27909877 -0.27681995
## 2007  1.46389075 -0.06141403 -0.27915444 -0.27880104 -0.27909877 -0.27681995
## 2008  1.46389075 -0.06141403 -0.27915444 -0.27880104 -0.27909877 -0.27681995
## 2009  1.46389075 -0.06141403 -0.27915444 -0.27880104 -0.27909877 -0.27681995
## 2010  1.46389075 -0.06141403 -0.27915444 -0.27880104 -0.27909877 -0.27681995
## 2011  1.46389075 -0.06141403 -0.27915444 -0.27880104 -0.27909877 -0.27681995
## 2012  1.46389075 -0.06141403 -0.27915444 -0.27880104 -0.27909877 -0.27681995
## 2013  1.46389075 -0.06141403 -0.27915444 -0.27880104 -0.27909877 -0.27681995
## 2014  1.46389075 -0.06141403 -0.27915444 -0.27880104 -0.27909877 -0.27681995
## 2015  1.46389075 -0.06141403 -0.27915444 -0.27880104 -0.27909877 -0.27681995
##              Jul         Aug         Sep         Oct         Nov         Dec
## 2003 -0.26917925 -0.28014403  0.25147571  0.08088681 -0.02351213 -0.04812964
## 2004 -0.26917925 -0.28014403  0.25147571  0.08088681 -0.02351213 -0.04812964
## 2005 -0.26917925 -0.28014403  0.25147571  0.08088681 -0.02351213 -0.04812964
## 2006 -0.26917925 -0.28014403  0.25147571  0.08088681 -0.02351213 -0.04812964
## 2007 -0.26917925 -0.28014403  0.25147571  0.08088681 -0.02351213 -0.04812964
## 2008 -0.26917925 -0.28014403  0.25147571  0.08088681 -0.02351213 -0.04812964
## 2009 -0.26917925 -0.28014403  0.25147571  0.08088681 -0.02351213 -0.04812964
## 2010 -0.26917925 -0.28014403  0.25147571  0.08088681 -0.02351213 -0.04812964
## 2011 -0.26917925 -0.28014403  0.25147571  0.08088681 -0.02351213 -0.04812964
## 2012 -0.26917925 -0.28014403  0.25147571  0.08088681 -0.02351213 -0.04812964
## 2013 -0.26917925 -0.28014403  0.25147571  0.08088681 -0.02351213 -0.04812964
## 2014 -0.26917925 -0.28014403  0.25147571  0.08088681 -0.02351213 -0.04812964
## 2015 -0.26917925 -0.28014403  0.25147571  0.08088681 -0.02351213 -0.04812964
## 
## $trend
##             Jan        Feb        Mar        Apr        May        Jun
## 2003         NA         NA         NA         NA         NA         NA
## 2004 0.27787867 0.27787867 0.30152926 0.31923330 0.34089496 0.34870505
## 2005 0.22884364 0.22884364 0.26657829 0.28469511 0.24649709 0.21255564
## 2006 0.67946010 0.67946010 0.68912625 0.70843514 0.74863062 0.79832636
## 2007 0.57746783 0.57746783 0.52964201 0.48374081 0.46922639 0.43364434
## 2008 0.25813344 0.25813344 0.23490787 0.19061995 0.14641588 0.14622915
## 2009 0.08352613 0.08352613 0.11610961 0.14869309 0.14869309 0.12573810
## 2010 0.06516696 0.06516696 0.03258348 0.00000000 0.00000000 0.00000000
## 2011 0.19784742 0.19784742 0.19784742 0.22067597 0.24350452 0.24350452
## 2012 0.20631515 0.20631515 0.25973396 0.30813048 0.32092238 0.33873657
## 2013 0.22050245 0.22050245 0.16708364 0.12137711 0.11127519 0.09346101
## 2014 0.05826397 0.05826397 0.05826397 0.03274543 0.01787516 0.05141720
## 2015 0.48471836 0.48471836 0.48471836 0.51553690 0.54352075 0.51779228
##             Jul        Aug        Sep        Oct        Nov        Dec
## 2003 0.32146492 0.31294572 0.27787867 0.27787867 0.27787867 0.27787867
## 2004 0.27002770 0.21999605 0.22884364 0.22884364 0.22884364 0.22884364
## 2005 0.41036422 0.65149708 0.67946010 0.67946010 0.67946010 0.67946010
## 2006 0.73427921 0.61427844 0.57746783 0.57746783 0.57746783 0.57746783
## 2007 0.33631739 0.25813344 0.25813344 0.25813344 0.25813344 0.25813344
## 2008 0.10754705 0.06471805 0.08352613 0.08352613 0.08352613 0.08352613
## 2009 0.10278312 0.08397504 0.06516696 0.06516696 0.06516696 0.06516696
## 2010 0.09892371 0.19784742 0.19784742 0.19784742 0.19784742 0.19784742
## 2011 0.22490983 0.20631515 0.20631515 0.20631515 0.20631515 0.20631515
## 2012 0.25840754 0.19929048 0.22050245 0.22050245 0.22050245 0.22050245
## 2013 0.09707446 0.07947594 0.05826397 0.05826397 0.05826397 0.05826397
## 2014 0.25632271 0.46152641 0.48471836 0.48471836 0.48471836 0.48471836
## 2015         NA         NA         NA         NA         NA         NA
## 
## $random
##                Jan           Feb           Mar           Apr           May
## 2003            NA            NA            NA            NA            NA
## 2004 -0.0924753203 -0.2164646348 -0.0223748205 -0.0404322662 -0.0617961909
## 2005 -1.4565421894  0.0449125711  0.0125761481 -0.0058940679  0.0326016800
## 2006  3.2089176151  0.2654085936 -0.4099718074 -0.4296340987 -0.4695318518
## 2007  1.3143461126 -0.5160537979 -0.2504875684 -0.2049397690 -0.1901276210
## 2008 -0.2427342498 -0.1967194033  0.0442465695  0.0881810845  0.1326828839
## 2009 -1.5474168844  0.4292818071  0.1630448303  0.1301079485  0.1304056766
## 2010 -1.5290577110 -0.0037529235  0.2465709614  0.2788010373  0.2790987655
## 2011  0.7124308676 -0.1364333859  0.0813070202  0.0581250688  0.0355942485
## 2012  0.2576907594 -0.1449011181  0.0194204846 -0.0293294412 -0.0418236176
## 2013 -1.6843932000  0.3499987945  0.1120707970  0.1574239285  0.1678235730
## 2014 -1.4354319752  0.0031500653  0.2208904714  0.2460556050  0.2612236034
## 2015  2.5063953415  0.1333025980 -0.2055639199 -0.2367358634 -0.2644219835
##                Jun           Jul           Aug           Sep           Oct
## 2003            NA -0.0522856654 -0.0328016858 -0.5293543784  0.4826595550
## 2004 -0.0718851051 -0.0008484524  0.0601479820  0.0872948546  0.3889774029
## 2005  0.0642643105 -0.1411849649 -0.3713530500  0.5423100441 -0.5324671986
## 2006 -0.5215064131 -0.4650999590 -0.3341344116  0.8762898196 -0.1990491151
## 2007 -0.1568243907 -0.0671381337  0.0220105939  0.0478044541  0.1664761805
## 2008  0.1305908012  0.1616321987  0.2154259796 -0.3350018404 -0.1644129441
## 2009  0.1510818465  0.1663961356  0.1961689943  0.4653608259 -0.1460537708
## 2010  0.2768199491  0.1702555419  0.0822966113 -0.4493231294 -0.2787342331
## 2011  0.0333154321  0.0442694173  0.0738288791 -0.4577908617  0.2606831976
## 2012 -0.0619166191  0.0107717114  0.0808535516  0.8100731259  0.1259611672
## 2013  0.1833589419  0.1721047969  0.2006680955 -0.3097396783  0.4732940981
## 2014  0.2254027478  0.0128565399 -0.1813823737 -0.7361940696 -0.5656051733
## 2015 -0.2409723349            NA            NA            NA            NA
##                Nov           Dec
## 2003 -0.2543665402  0.6140758571
## 2004  0.4572653387  0.1879563870
## 2005 -0.4392754558 -0.6313304645
## 2006  0.3959825507 -0.0699060530
## 2007  0.3207799683 -0.2100038004
## 2008 -0.0600140023  0.5155231750
## 2009 -0.0416548289 -0.0170373207
## 2010 -0.1743352913 -0.1497177830
## 2011 -0.1828030235 -0.1581855153
## 2012  0.2305501271 -0.1723728097
## 2013 -0.0347518401 -0.0101343319
## 2014 -0.2056478364  0.1128618258
## 2015            NA            NA
## 
## $figure
##  [1]  1.46389075 -0.06141403 -0.27915444 -0.27880104 -0.27909877 -0.27681995
##  [7] -0.26917925 -0.28014403  0.25147571  0.08088681 -0.02351213 -0.04812964
## 
## $type
## [1] "additive"
## 
## attr(,"class")
## [1] "decomposed.ts"
fit.zoncan<-stl(zoncan, "periodic")
plot(fit.zoncan, main="Chincol-Canelo")

monthplot(zoncan, main="Chincol-Canelo")

seasonplot(zoncan, main="Chincol-Canelo")

##
#Chincol-Notro
decompose(zonnot)
## $x
##            Jan       Feb       Mar       Apr       May       Jun       Jul
## 2003 0.0000000 0.0000000 0.6247813 0.0000000 0.0000000 0.0000000 0.0000000
## 2004 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
## 2005 1.0939004 0.5157085 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
## 2006 0.2559495 2.1878008 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
## 2007 1.6003414 0.5341880 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
## 2008 2.9585799 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
## 2009 0.9885167 0.7328334 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
## 2010 0.0000000 0.4393596 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
## 2011 2.7870680 0.0000000 0.3253937 0.0000000 0.0000000 0.0000000 0.0000000
## 2012 2.5287008 1.0864841 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
## 2013 0.1451817 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
## 2014 0.4597913 0.6747638 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
## 2015 0.9230769 1.1538462 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
##            Aug       Sep       Oct       Nov       Dec
## 2003 0.0000000 1.0016026 0.4843412 2.1544666 0.6004455
## 2004 0.0000000 2.4074573 0.0000000 0.2117460 1.0071761
## 2005 0.0000000 0.0000000 0.2144975 0.7174768 0.0000000
## 2006 0.0000000 0.0000000 0.5152249 0.0000000 1.0525873
## 2007 0.0000000 0.0000000 1.6608475 0.0000000 1.4792899
## 2008 0.0000000 0.0000000 2.5625081 0.0000000 0.0000000
## 2009 0.0000000 1.0311404 0.0000000 1.5384615 0.4748338
## 2010 0.3230705 2.3741690 2.8490028 0.0000000 0.9496676
## 2011 0.0000000 2.3741690 2.8490028 1.8844458 1.1708231
## 2012 0.0000000 2.1367521 0.0000000 0.6410256 0.4273504
## 2013 0.0000000 2.1770682 0.8280202 0.3993929 1.0497145
## 2014 0.0000000 1.8315018 0.9841745 0.4180602 0.6228589
## 2015 0.0000000 0.2590003 0.4798695 0.0000000 0.2616431
## 
## $seasonal
##             Jan        Feb        Mar        Apr        May        Jun
## 2003  0.6773885  0.1427116 -0.4380091 -0.4625312 -0.4550349 -0.4463777
## 2004  0.6773885  0.1427116 -0.4380091 -0.4625312 -0.4550349 -0.4463777
## 2005  0.6773885  0.1427116 -0.4380091 -0.4625312 -0.4550349 -0.4463777
## 2006  0.6773885  0.1427116 -0.4380091 -0.4625312 -0.4550349 -0.4463777
## 2007  0.6773885  0.1427116 -0.4380091 -0.4625312 -0.4550349 -0.4463777
## 2008  0.6773885  0.1427116 -0.4380091 -0.4625312 -0.4550349 -0.4463777
## 2009  0.6773885  0.1427116 -0.4380091 -0.4625312 -0.4550349 -0.4463777
## 2010  0.6773885  0.1427116 -0.4380091 -0.4625312 -0.4550349 -0.4463777
## 2011  0.6773885  0.1427116 -0.4380091 -0.4625312 -0.4550349 -0.4463777
## 2012  0.6773885  0.1427116 -0.4380091 -0.4625312 -0.4550349 -0.4463777
## 2013  0.6773885  0.1427116 -0.4380091 -0.4625312 -0.4550349 -0.4463777
## 2014  0.6773885  0.1427116 -0.4380091 -0.4625312 -0.4550349 -0.4463777
## 2015  0.6773885  0.1427116 -0.4380091 -0.4625312 -0.4550349 -0.4463777
##             Jul        Aug        Sep        Oct        Nov        Dec
## 2003 -0.4608245 -0.4411135  0.8079486  0.6112646  0.1960526  0.2685252
## 2004 -0.4608245 -0.4411135  0.8079486  0.6112646  0.1960526  0.2685252
## 2005 -0.4608245 -0.4411135  0.8079486  0.6112646  0.1960526  0.2685252
## 2006 -0.4608245 -0.4411135  0.8079486  0.6112646  0.1960526  0.2685252
## 2007 -0.4608245 -0.4411135  0.8079486  0.6112646  0.1960526  0.2685252
## 2008 -0.4608245 -0.4411135  0.8079486  0.6112646  0.1960526  0.2685252
## 2009 -0.4608245 -0.4411135  0.8079486  0.6112646  0.1960526  0.2685252
## 2010 -0.4608245 -0.4411135  0.8079486  0.6112646  0.1960526  0.2685252
## 2011 -0.4608245 -0.4411135  0.8079486  0.6112646  0.1960526  0.2685252
## 2012 -0.4608245 -0.4411135  0.8079486  0.6112646  0.1960526  0.2685252
## 2013 -0.4608245 -0.4411135  0.8079486  0.6112646  0.1960526  0.2685252
## 2014 -0.4608245 -0.4411135  0.8079486  0.6112646  0.1960526  0.2685252
## 2015 -0.4608245 -0.4411135  0.8079486  0.6112646  0.1960526  0.2685252
## 
## $trend
##            Jan       Feb       Mar       Apr       May       Jun       Jul
## 2003        NA        NA        NA        NA        NA        NA 0.4054698
## 2004 0.3534047 0.3534047 0.4119819 0.4503783 0.3492508 0.2852512 0.3477775
## 2005 0.4363324 0.4363324 0.3360216 0.2446483 0.2746578 0.2537643 0.1768840
## 2006 0.2813104 0.2813104 0.2813104 0.2938407 0.2764761 0.2904391 0.3903132
## 2007 0.3085285 0.3085285 0.3085285 0.3562627 0.4039970 0.4217763 0.4961488
## 2008 0.5082264 0.5082264 0.5082264 0.5457956 0.5833648 0.5217277 0.3780047
## 2009 0.3569882 0.3569882 0.3999524 0.3361454 0.2934768 0.3773641 0.3559606
## 2010 0.2903163 0.3037776 0.3731983 0.5478663 0.6024722 0.5581544 0.6940670
## 2011 0.8006976 0.7872364 0.7737751 0.7737751 0.8522937 0.9400271 0.9384766
## 2012 0.9911355 0.9911355 0.9812431 0.8526423 0.6821247 0.5993375 0.4690461
## 2013 0.2791925 0.2791925 0.2808723 0.3170530 0.3414858 0.3573496 0.3963902
## 2014 0.4657292 0.4657292 0.4513306 0.4434385 0.4507227 0.4337149 0.4352328
## 2015 0.4944599 0.4944599 0.4289390 0.3424054 0.3039735 0.2715037        NA
##            Aug       Sep       Oct       Nov       Dec
## 2003 0.4054698 0.3794372 0.3534047 0.3534047 0.3534047
## 2004 0.4148445 0.4363324 0.4363324 0.4363324 0.4363324
## 2005 0.2116399 0.2813104 0.2813104 0.2813104 0.2813104
## 2006 0.3774290 0.3085285 0.3085285 0.3085285 0.3085285
## 2007 0.5304843 0.5082264 0.5082264 0.5082264 0.5082264
## 2008 0.3264535 0.3569882 0.3569882 0.3569882 0.3569882
## 2009 0.3025444 0.2903163 0.2903163 0.2903163 0.2903163
## 2010 0.7918881 0.7871396 0.8006976 0.8006976 0.8006976
## 2011 0.9729814 1.0046935 0.9911355 0.9911355 0.9911355
## 2012 0.3244627 0.2791925 0.2791925 0.2791925 0.2791925
## 2013 0.4376141 0.4657292 0.4657292 0.4657292 0.4657292
## 2014 0.4744981 0.4944599 0.4944599 0.4944599 0.4944599
## 2015        NA        NA        NA        NA        NA
## 
## $random
##               Jan          Feb          Mar          Apr          May
## 2003           NA           NA           NA           NA           NA
## 2004 -1.030793156 -0.496116307  0.026027156  0.012152895  0.105784161
## 2005 -0.019820441 -0.063335523  0.101987465  0.217882930  0.180377105
## 2006 -0.702749328  1.763778798  0.156698720  0.168690546  0.178558788
## 2007  0.614424449  0.082947926  0.129480637  0.106268497  0.051037905
## 2008  1.772964943 -0.650938089 -0.070217344 -0.083264398 -0.128329902
## 2009 -0.045859945  0.233133551  0.038056733  0.126385856  0.161558149
## 2010 -0.967704772 -0.007129603  0.064810759 -0.085335082 -0.147437284
## 2011  1.308981871 -0.929948014 -0.010372274 -0.311243863 -0.397258751
## 2012  0.860176792 -0.047362976 -0.543233997 -0.390111037 -0.227089726
## 2013 -0.811399275 -0.421904134  0.157136774  0.145478232  0.113549106
## 2014 -0.683326478  0.066322949 -0.013321540  0.019092768  0.004312223
## 2015 -0.248771444  0.516674637  0.009070127  0.120125871  0.151061440
##               Jun          Jul          Aug          Sep          Oct
## 2003           NA  0.055354762  0.035643762 -0.185783267 -0.480327994
## 2004  0.161126563  0.113047067  0.026269030  1.163176368 -1.047596937
## 2005  0.192613476  0.283940564  0.229473669 -1.089258994 -0.678077505
## 2006  0.155938667  0.070511333  0.063684539 -1.116477077 -0.404568146
## 2007  0.024601443 -0.035324309 -0.089370745 -1.316175058  0.541356526
## 2008 -0.075350005  0.082819836  0.114660077 -1.164936796  1.594255354
## 2009  0.069013659  0.104863910  0.138569182 -0.067124451 -0.901580857
## 2010 -0.111776646 -0.233242425 -0.027704147  0.779080861  1.437040632
## 2011 -0.493649321 -0.477652034 -0.531867905  0.561526887  1.246602802
## 2012 -0.152959710 -0.008221593  0.116650873  1.049611034 -0.890457068
## 2013  0.089028117  0.064434346  0.003499455  0.903390362 -0.248973614
## 2014  0.012662884  0.025591759 -0.033384574  0.529093346 -0.121549977
## 2015  0.174874089           NA           NA           NA           NA
##               Nov          Dec
## 2003  1.605009412 -0.021484340
## 2004 -0.420638951  0.302318563
## 2005  0.240113832 -0.549835589
## 2006 -0.504581029  0.475533587
## 2007 -0.704279010  0.702538287
## 2008 -0.553040748 -0.625513391
## 2009  1.052092694 -0.084007679
## 2010 -0.996750204 -0.119555231
## 2011  0.697257750 -0.088837588
## 2012  0.165780586 -0.120367272
## 2013 -0.262388882  0.315460030
## 2014 -0.272452237 -0.140126159
## 2015           NA           NA
## 
## $figure
##  [1]  0.6773885  0.1427116 -0.4380091 -0.4625312 -0.4550349 -0.4463777
##  [7] -0.4608245 -0.4411135  0.8079486  0.6112646  0.1960526  0.2685252
## 
## $type
## [1] "additive"
## 
## attr(,"class")
## [1] "decomposed.ts"
fit.zonnot<-stl(zonnot, "periodic")
plot(fit.zonnot, main="Chincol-Notro")

monthplot(zonnot, main="Chincol-Notro")

seasonplot(zonnot, main="Chincol-Notro")

Very useful information indeed, with a bunch of applications for population ecology, conservation biology, wildlife management, etc.

ARIMA models

Autoregressive integrated moving average (aka ARIMA) are intended to be used with time series data as they account for seasonality and temporal autocorrelation. Below we will compare one species in two habitats as an example using ARIMA models of first order. ARIMA could be decomposed in AR-I-MA and 0 or 1 indicate if each component (autoregressive, integrated, or moving average) is present or not in the model. A detailed explanation of these models is beyond the scope of this lesson, but there are many good books on this subject.

##Rayadito-Canelo
m1.aphcan=arima(aphcan,order=c(1,1,1),seasonal=list(order=c(0,1,1), period=12))
m1.aphcan
## 
## Call:
## arima(x = aphcan, order = c(1, 1, 1), seasonal = list(order = c(0, 1, 1), period = 12))
## 
## Coefficients:
##          ar1      ma1     sma1
##       0.3233  -0.9927  -0.9990
## s.e.  0.0851   0.1312   0.3394
## 
## sigma^2 estimated as 5.162:  log likelihood = -338.61,  aic = 683.22
#Diagnosing ARIMA model
tsdiag(m1.aphcan)

Box.test(m1.aphcan$residuals,lag=1)
## 
##  Box-Pierce test
## 
## data:  m1.aphcan$residuals
## X-squared = 0.69424, df = 1, p-value = 0.4047
#Estimating ma1 significance
(1-pnorm(abs(m1.aphcan$coef)/sqrt(diag(m1.aphcan$var.coef))))*2
##          ar1          ma1         sma1 
## 1.449306e-04 3.907985e-14 3.245826e-03
# Residuals
plot(window(rstandard(m1.aphcan),start=c(2003,2)), ylab='Standardized Residuals',type='o')
abline(h=0)

# ACF
acf(as.vector(window(rstandard(m1.aphcan),start=c(2003,2))), lag.max=36)

hist(window(rstandard(m1.aphcan),start=c(2003,2)), xlab='Standardized Residuals')

##Rayadito-Notro
m1.aphnot=arima(aphnot,order=c(1,1,1),seasonal=list(order=c(0,1,1), period=12))
m1.aphnot
## 
## Call:
## arima(x = aphnot, order = c(1, 1, 1), seasonal = list(order = c(0, 1, 1), period = 12))
## 
## Coefficients:
##          ar1      ma1     sma1
##       0.2302  -0.9569  -0.9093
## s.e.  0.0886   0.0354   0.1615
## 
## sigma^2 estimated as 6.609:  log likelihood = -349.66,  aic = 705.31
#Diagnosing ARIMA model
tsdiag(m1.aphnot)

Box.test(m1.aphnot$residuals,lag=1)
## 
##  Box-Pierce test
## 
## data:  m1.aphnot$residuals
## X-squared = 0.11772, df = 1, p-value = 0.7315
#Estimating ma1 significance
(1-pnorm(abs(m1.aphnot$coef)/sqrt(diag(m1.aphnot$var.coef))))*2
##          ar1          ma1         sma1 
## 9.335160e-03 0.000000e+00 1.778289e-08
# Residuals
plot(window(rstandard(m1.aphnot),start=c(2003,2)), ylab='Standardized Residuals',type='o')
abline(h=0)

# ACF
acf(as.vector(window(rstandard(m1.aphnot),start=c(2003,2))), lag.max=36)

hist(window(rstandard(m1.aphnot),start=c(2003,2)), xlab='Standardized Residuals')

Final thoughts

aaa

Session

sessionInfo()
## R version 4.1.0 (2021-05-18)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Big Sur 10.16
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] astsa_1.14    forecast_8.16 TSA_1.3      
## 
## loaded via a namespace (and not attached):
##  [1] zoo_1.8-9         locfit_1.5-9.5    tidyselect_1.1.2  xfun_0.30        
##  [5] bslib_0.3.1       urca_1.3-0        purrr_0.3.4       splines_4.1.0    
##  [9] lattice_0.20-45   colorspace_2.0-3  vctrs_0.4.0       generics_0.1.2   
## [13] htmltools_0.5.2   yaml_2.3.5        mgcv_1.8-40       utf8_1.2.2       
## [17] rlang_1.0.2       jquerylib_0.1.4   pillar_1.7.0      glue_1.6.2       
## [21] DBI_1.1.2         TTR_0.24.3        lifecycle_1.0.1   quantmod_0.4.18  
## [25] stringr_1.4.0     timeDate_3043.102 munsell_0.5.0     gtable_0.3.0     
## [29] leaps_3.1         evaluate_0.15     tseries_0.10-50   knitr_1.38       
## [33] fastmap_1.1.0     lmtest_0.9-40     curl_4.3.2        parallel_4.1.0   
## [37] fansi_1.0.3       highr_0.9         xts_0.12.1        Rcpp_1.0.8.3     
## [41] scales_1.2.0      jsonlite_1.8.0    fracdiff_1.5-1    ggplot2_3.3.5    
## [45] digest_0.6.29     stringi_1.7.6     dplyr_1.0.8       grid_4.1.0       
## [49] quadprog_1.5-8    cli_3.2.0         tools_4.1.0       magrittr_2.0.3   
## [53] sass_0.4.1        tibble_3.1.6      crayon_1.5.1      pkgconfig_2.0.3  
## [57] ellipsis_0.3.2    Matrix_1.4-1      assertthat_0.2.1  rmarkdown_2.13   
## [61] rstudioapi_0.13   R6_2.5.1          nnet_7.3-17       nlme_3.1-157     
## [65] compiler_4.1.0
footer.utf8.md


Licensing Creative Commons License
CC

Licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
2022 - Francisco E. Fontúrbel